// pages/home/collection/collection-dateils/index.js
import Dialog from "@vant/weapp/dialog/dialog";

const app = getApp();
const {
    AskPage
} = app._require('common/index');
const formMixin = app._require("mixins/form.mixin.js").default;
// const { handleMixin } = app._require("/action.js");
import {handleMixin} from "./action";

AskPage({

    name: "collection-details",
    mixins: [formMixin, handleMixin],
    data: {
        navBarHeight: app.globalData.navBarHeight, //导航栏高度
        activeNames: [],
        validate: [],
        type: '',
        processInstanceId: '',
        category: '',
        approvalStatus: '',
        userId: '',
        minData: new Date(1890, 0, 1).getTime(),
        maxData: new Date(2071, 1, 1).getTime(),
        model: {
            dataCount: 0,
            state: 2,
            executor: "",
            formId: "",
            shareId: "",
            makePhone: "",
            id: "",
            taskId: "",
            name: "",
            readonly: true,
            line: 0,
            description: "",
        },
        // 表单项列表
        formItemList: [],
        // 单选选中内容
        selectItemValue: {}
    },

    onShow() {
        wx.hideHomeButton();
        //检测更新
        app.checkProkectSystem();

    },
    onLoad(options) {

        console.log(options);

        this.setData({
            onLoadOption: options
        })
        const uniqueId = decodeURIComponent(options.scene);
        if (uniqueId != 'undefined') {
            //获取id
            this.getWxCodeInfo(uniqueId);
        } else {
            if (options) {
                this.setData({
                    "model.formId": options.formId || "",
                    "model.id": options.id || "",
                    "model.taskId": options.taskId || "",
                    state: options.state || 1,
                    dataCount: options.dataCount,
                    description: options.description,
                    type: options.type,
                    current_type: options.current_type,
                    processInstanceId: options.processInstanceId || "",
                    userId: options.userId,
                    approvalStatus: options.approvalStatus || "",
                    category: options.category || "",
                    clickNext: options.clickNext,
                    formShow: options.clickNext,
                    goBackLast: options.goBackLast,
                    reason: options.reason,
                    verify: options.verify,
                    isCopy: options.isCopy
                });

                let userInfo = app.user.userInfo ?? {};
                if (options.cityCode) {
                    userInfo.cityCode = options.cityCode;
                    userInfo.departmentId = options.departmentId;
                    userInfo.governmentId = options.governmentId;
                    userInfo.orgCategoryId = options.orgCategoryId;
                    app.user.userInfo = userInfo;
                }
            }
            this.initForm();
        }
    },
    async initForm() {
        let model = {};

        if (this.data.model.id) {
            model = await this.initDetailsData();
        }
        this.initDetails(model);
    },
    // 获取填报数据
    async initDetailsData() {
        try {

            let request_url = "form/reportDetail";
            if (this.data.type == 'sb_report') {
                //上报
                request_url = 'form/sbReportDetail'
            }

            const response = await this.$_server(request_url, {
                data: {
                    formId: this.data.model.formId || "",
                    dataFormId: this.data.model.id || "",
                },
            });
            let {data} = response;
            console.log(data);
            if (data.code !== 200) {
                throw data;
            }
            let resourceUrl = this.data.$_config.url;

            const formData = data.data;

            // 组装数据
            const checkData = (item) => {
                let itemData = "";
                console.log("-----------------");
                console.log(item)
                if (["5", "8", "10"].includes(item.valueKindId.toString())) {

                    itemData = item.data ? item.data.path.map(cur => {
                        return {
                            src: resourceUrl + (cur.indexOf("\/") === 0 ? cur : "/" + cur),
                            fileName: this.getName(cur)
                        }
                    }) : [];
                } else if (item.valueKindId.toString() === "9") {
                    if (item.data && item.data.path && item.data.path.length) {
                        const cur = item.data.path[0];
                        itemData = item.data ? resourceUrl + (cur.indexOf("\/") === 0 ? cur : "/" + cur) : ""
                    } else {
                        itemData = ""
                    }
                } else if (item.valueKindId.toString() === "4") {
                    if (item.data) {
                        itemData = {
                            cityCode: null,
                            cityInfo: item.data.cityInfo,
                            info: item.data.cityAddress,
                            longitude: item.data.longitude,
                            latitude: item.data.latitude
                        }
                    } else {
                        itemData = {}
                    }
                }
                return itemData;
            };

            // 除表格内的表单项数据
            formData.items.forEach(item => {
                if (item.valueKindId.toString() === "7") {
                    item.itemValue = item.itemValue.split(",");
                }
                if (item.valueKindId.toString() === "9") {
                    this.setData({
                        ["model." + item.itemId]: checkData(item)
                    });
                } else if (["3", "11"].includes(item.valueKindId.toString()) && item.itemValue) {
                    this.setData({
                        ["model." + item.itemId]: new Date(item.itemValue.replace(/-/g, "/")).getTime()
                    });
                } else if (item.valueKindId.toString() === "4") {
                    this.setData({
                        ["model." + item.itemId]: checkData(item) || item.data
                    });
                } else {
                    this.setData({
                        ["model." + item.itemId]: item.itemValue || checkData(item) || item.data
                    });
                }
            });

            // 表格内的表单项数据
            formData.list.forEach(item => {
                const tableData = [];
                const maxLineNum = Math.max(...item.data.map((item) => item.lineNum));
                for (let i = 0; i < maxLineNum; i++) {
                    const rowData = {}
                    item.data.filter(it => it.lineNum === i + 1).forEach(cur => {
                        if (cur.valueKindId.toString() === "7") {
                            rowData[cur.itemId] = cur.itemValue ? cur.itemValue.split(",") : [];
                        } else if (cur.valueKindId.toString() === "9") {
                            rowData[cur.itemId] = checkData(cur);
                        } else if (["3", "11"].includes(cur.valueKindId.toString()) && cur.itemValue) {
                            rowData[cur.itemId] = new Date(item.itemValue.replace(/-/g, "/")).getTime();
                        } else if (cur.valueKindId.toString() === "4") {
                            rowData[cur.itemId] = checkData(cur) || cur.data;
                        } else {
                            rowData[cur.itemId] = cur.itemValue || checkData(cur) || cur.data;
                        }
                    });
                    tableData.push(rowData);
                }
                this.setData({
                    ["model." + item.formId]: tableData
                });
            });

            return formData;

        } catch (error) {
            console.log(error);
            // statements
            if (error.message) {
                wx.showToast({
                    mask: true,
                    title: error.message,
                    icon: "none",
                    duration: 2000,
                });
            } else {
                throw error;
            }
        }
    },
    // 获取表单模板
    async initDetails(dataResponse = {}) {
        try {
            let {formId} = this.data.model;

            let response = "";
            if (this.data.type == 'share') {
                response = await this.$_server("form/getForwardt", {
                    data: {
                        id: formId,
                        taskId: this.data.model.taskId
                    },
                });
            } else if (this.data.type == 'sb_share') {
                //shareFormDetail
                response = await this.$_server("form/shareFormDetail", {
                    params: {
                        formId: "?formId=" + formId,
                    },
                });
            } else {
                response = await this.$_server("form/get", {
                    data: {
                        id: formId,
                    },
                });
            }
            let {data} = response;
            if (data.code !== 200) {
                throw data;
            }

            console.log(data);

            let {data: list} = data;

            let descriptionType = data.data.descriptionType;
            let description = data.data.description;
            //新增描述
            this.setData({
                "description": description,
                "descriptionType": descriptionType
            })
            if (descriptionType == 2) {
                this.loadRichHtml(description);
            }

            // 组装表单项结构，表格根据数据组装行数
            const getItem = (arr) => {
                arr.forEach(item => {
                    if (item.itemType === 0) {
                        const activeNames = this.data.activeNames;
                        activeNames.push(item.id);
                        this.setData({
                            activeNames: activeNames
                        });
                        item.items = getItem(item.items);
                    } else if (item.itemType === 1) {
                        const activeNames = this.data.activeNames;
                        activeNames.push(item.id);
                        this.setData({
                            activeNames: activeNames
                        });
                        item.rows = [];
                        let rowData = [];
                        if (dataResponse.list) {
                            rowData = dataResponse.list.filter(cur => cur.formId === item.childrenFormId);
                            let lineList = [1];
                            if (rowData.length) {
                                lineList = rowData[0].data.map(cur => cur.lineNum);
                            }
                            const maxLine = Math.max(...lineList);
                            for (let i = 0; i < maxLine; i++) {
                                item.rows.push({
                                    id: this.getRandomId(),
                                    items: getItem(item.items)
                                });
                            }
                        } else {
                            item.rows.push({
                                id: this.getRandomId(),
                                items: getItem(item.items)
                            });
                        }
                    } else {
                        if (["6", "7"].includes(item.valueKindId.toString())) {
                            const options = item.options;
                            item.options = options.map(cur => {
                                return {
                                    value: cur.name || cur.value,
                                    label: cur.name || cur.label,
                                    id: cur.id
                                }
                            });
                            item.placeholder = "请选择";
                        }
                        if (["3", "11"].includes(item.valueKindId.toString())) {
                            item.placeholder = "请选择";
                        }
                    }
                });
                return arr;
            };

            const formItemList = getItem(list.items);

            const checkSelect = (arr) => {
                arr.forEach(item => {
                    if (item.itemType === 0) {
                        checkSelect(item.items);
                    } else if (item.itemType === 2) {
                        if (item.valueKindId.toString() === "6") {
                            if (dataResponse.items) {
                                // 对应数据
                                const data = dataResponse.items.filter(it => it.itemId === item.id);
                                if (data.length) {
                                    // 对应选项值
                                    const option = item.options.filter(it => it.value === data[0].itemValue);
                                    if (option.length) {
                                        this.setData({
                                            ["selectItemValue." + item.id]: option[0].id
                                        })
                                    }
                                }
                            }
                        }
                    }
                });
            };

            checkSelect(list.items);

            //新增描述
            this.setData({
                "model.description": list.description || "",
                "model.name": list.name || "",
                formItemList: formItemList || []
            });
        } catch (error) {
            let errorTitle = error.message || "操作失败";
            this.setData({
                "loadError": true,
                "errorTitle": errorTitle
            })
        }
    },
    // 获取文件名称
    getName(val) {
        if (!val.includes("?")) return val;
        const params = val.split("?")[1].split("&");
        const obj = {};
        params.forEach((item) => {
            obj[item.split("=")[0]] = item.split("=")[1];
        });
        return obj.name;
    },
    //单选
    onSelectClick(e) {
        let {key, keyid, value} = e.currentTarget.dataset;
        let {value: item} = e.detail;

        if (Array.isArray(key)) {
            // 在表格中
            let str = "model.";
            key.forEach(item => {
                if (typeof item === "number") {
                    str += "[" + item + "]";
                } else {
                    str += item;
                }
            });

            // 判断新值旧值是否相等，相等的话就是取消选中
            let _value = value || "";
            if (_value === item.value) {
                _value = "";
            } else {
                _value = item.value;
            }

            const opt = {};
            opt[str] = _value;
            this.setData(opt);
        } else {
            // 判断新值旧值是否相等，相等的话就是取消选中
            let _value = this.data.model[key] || "";
            if (_value === item.value) {
                _value = "";
            } else {
                _value = item.value;
            }
            // 赋值
            this.setData({
                ["model." + key]: _value,
                ["selectItemValue." + keyid]: _value.length > 0 ? item.id : "",
            });
        }
    },
    //多选
    onCascaderClick(e) {
        let {key} = e.currentTarget.dataset;
        let {value: item} = e.detail;
        let _key = "model." + key;
        if (Array.isArray(key)) {
            // 在表格中
            _key = "model.";
            key.forEach(it => {
                if (typeof it === "number") {
                    _key += "[" + it + "]";
                } else {
                    _key += it;
                }
            });
        }
        this.setData({
            [_key]: item,
        });
    },

    locationChange(e) {
        // 真实key，可能是表格中，就是数组
        const {key: sKey} = e.currentTarget.dataset;
        // 控件选的是定位还是输入详细地址
        const {key} = e.detail.currentTarget.dataset;
        const {value} = e.detail.detail;
        let _key = "";
        if (key === "address") {
            _key = sKey;
        } else {
            if (Array.isArray(sKey)) {
                _key = [].concat([], sKey);
                _key.push("info");
            } else {
                _key = key.replace("address", sKey);
            }
        }
        this.setModel({
            currentTarget: {
                dataset: {
                    key: _key
                }
            },
            detail: {
                value
            },
        });
    },
    onTextAreaChange(e) {
        const {key: sKey} = e.currentTarget.dataset;
        const value = e.detail;

        this.setModel({
            currentTarget: {
                dataset: {
                    key: sKey,
                },
            },
            detail: {
                value: value,
            },
        });
    },
    async sure(e) {
        let {descriptiontype, draft} = e.currentTarget.dataset;
        if (draft === "1") {
            this.saveInfo("draft");
        } else {
            if (descriptiontype == 2) {
                this.setData({
                    "formShow": true,
                    "descriptionType": ""
                })
            } else {
                this.saveInfo();
            }
        }
    },
    clearData(item) {
        if (item.cascadeId) {
            const optionValue = this.data.selectItemValue[item.cascadeId];
            return !item.cascadeOptionIds.includes(optionValue);
        } else {
            return false;
        }
    },
    async saveInfo(saveType) {
        let params = {};
        let items = [];
        let {model, formItemList} = this.data;
        let checkForm = {
            result: true,
            msg: ""
        }

        const getItem = (arr, rowIndex, tableId) => {
            let list = []

            arr.forEach((item, index) => {
                if (item.itemType === 0) {
                    const childrenList = getItem(item.items);
                    list.push({
                        itemId: item.id,
                        itemType: 0,
                        sort: index,
                        children: {
                            formId: item.childrenFormId,
                            items: childrenList
                        }
                    });
                } else if (item.itemType === 1) {
                    const childrenList = getItem(item.rows, -1, item.childrenFormId);
                    list.push({
                        itemId: item.id,
                        itemType: 0,
                        sort: index,
                        children: {
                            formId: item.childrenFormId,
                            items: childrenList
                        }
                    });
                } else if (item.itemType === 2) {
                    let data = {};
                    let sourceData = this.data.model[item.id];

                    if (tableId) {
                        sourceData = this.data.model[tableId] ? this.data.model[tableId][rowIndex] ? this.data.model[tableId][rowIndex][item.id] : "" : "";
                    }
                    if (["5", "8", "10"].includes(item.valueKindId.toString())) {
                        data.extData = sourceData ? sourceData.map(cur => {
                            return cur.src.substring(this.data.$_config.url.length);
                        }) : [];
                        if (this.clearData(item)) {
                            data.extData = [];
                        } else if (checkForm.result && item.required && !data.extData.length) {
                            checkForm = {
                                result: false,
                                msg: "请上传" + item.name
                            }
                        }
                    } else if (item.valueKindId.toString() === "9") {
                        if (typeof sourceData === "string") {
                            data.extData = sourceData ? [sourceData.substring(this.data.$_config.url.length)] : [];
                        } else {
                            data.extData = [];
                        }
                        if (this.clearData(item)) {
                            data.extData = [];
                        } else if (checkForm.result && item.required && !data.extData.length) {
                            checkForm = {
                                result: false,
                                msg: "请上传" + item.name
                            }
                        }
                    } else if (item.valueKindId.toString() === "4") {
                        data.extData = sourceData ? {
                            cityAddress: sourceData.info,
                            cityName: sourceData.cityInfo,
                            latitude: sourceData.latitude,
                            longitude: sourceData.longitude
                        } : {};
                        if (this.clearData(item)) {
                            data.extData = {};
                        } else if (checkForm.result && item.required) {
                            if (!data.extData.cityName) {
                                checkForm = {
                                    result: false,
                                    msg: "请选择" + item.name
                                }
                            } else if (!data.extData.cityAddress) {
                                checkForm = {
                                    result: false,
                                    msg: "请填写详细地址"
                                }
                            }
                        }
                    } else if (item.valueKindId.toString() === "7") {
                        data.itemValue = sourceData ? sourceData.join(",") : "";
                        if (this.clearData(item)) {
                            data.itemValue = "";
                        } else if (checkForm.result && item.required && !data.itemValue) {
                            checkForm = {
                                result: false,
                                msg: "请选择" + item.name
                            }
                        }
                    } else if (item.valueKindId.toString() === "3") {
                        data.itemValue = (sourceData || sourceData === 0) ? new Date(sourceData).format("yyyy-MM-dd") : "";
                        if (this.clearData(item)) {
                            data.itemValue = "";
                        } else if (checkForm.result && item.required && !data.itemValue) {
                            checkForm = {
                                result: false,
                                msg: "请选择" + item.name
                            }
                        }
                    } else if (item.valueKindId.toString() === "11") {
                        data.itemValue = (sourceData || sourceData === 0) ? new Date(sourceData).format("yyyy-MM-dd hh:mm:ss") : "";
                        if (this.clearData(item)) {
                            data.itemValue = "";
                        } else if (checkForm.result && item.required && !data.itemValue) {
                            checkForm = {
                                result: false,
                                msg: "请选择" + item.name
                            }
                        }
                    } else {
                        data.itemValue = sourceData || "";
                        console.log(sourceData);
                        if (this.clearData(item)) {
                            data.itemValue = "";
                        } else if (checkForm.result && item.required && !data.itemValue) {
                            checkForm = {
                                result: false,
                                msg: (item.valueKindId.toString() === "6" ? "请选择" : "请填写") + item.name
                            }
                        } else if (checkForm.result) {


                            if (item.required) {
                                // 必填，有值


                                if ((item.valueLength && data.itemValue.length !== item.valueLength) || (item.valueKindId.toString() === "12" && !this.chk(data.itemValue))) {
                                    checkForm = {
                                        result: false,
                                        msg: "请填写正确的" + item.name
                                    }
                                }
                                if (item.valueKindId.toString() === "13" && this.chkd(data.itemValue)) {
                                    if (data.itemValue.split('.')[1] && data.itemValue.split('.')[1].length > 2) {
                                        checkForm = {
                                            result: false,
                                            msg: item.name + "最多保留2位小数"
                                        }
                                    }
                                }

                            } else {

                                // 非必填并且有值
                                if (item.valueLength & data.itemValue.length > 0) {
                                    if ((item.valueLength && data.itemValue && data.itemValue.length !== item.valueLength) || (item.valueKindId.toString() === "12" && !this.chk(data.itemValue))) {
                                        checkForm = {
                                            result: false,
                                            msg: "请填写正确的" + item.name
                                        }
                                    }

                                    if (item.valueKindId.toString() === "13" && !this.chkd(data.itemValue)) {
                                        if (data.itemValue.split('.')[1] && data.itemValue.split('.')[1].length > 2) {
                                            checkForm = {
                                                result: false,
                                                msg: item.name + "最多保留2位小数"
                                            }
                                        }
                                    }
                                }

                            }
                        }

                        //判断数字
                        // if (item.valueKindId.toString() === "12"){
                        //       //判断pc上输入数字异常
                        //    if(!this.chk(data.itemValue) ){
                        //     checkForm = {
                        //         result: false,
                        //         msg: "请填写正确的" + item.name
                        //     }
                        //         //  value=value.slice(0, -1)
                        //     }

                        // }
                        // console.log(checkForm);
                        // console.log(data.itemValue);

                    }

                    list.push({
                        itemId: item.id,
                        itemType: 2,
                        sort: index,
                        valueKindId: item.valueKindId,
                        ...data
                    });
                } else {
                    // 表格子项
                    const rowItem = getItem(item.items, index, tableId).map(it => {
                        return {
                            ...it,
                            lineNum: index + 1
                        }
                    });
                    list = list.concat([], rowItem);
                }
            });

            return list;
        };

        items = getItem(formItemList);

        if (saveType !== "draft" && !checkForm.result) {
            wx.askShowToastEx({
                mask: true,
                title: checkForm.msg,
                icon: "none",
                duration: 2000,
            });
            return;
        }

        const info = {
            collectorId: this.data.userId,
            processInstId: this.data.processInstanceId || "",
        }
        let _children = {};
        if (model.id !== "") {
            _children = {
                dataFormId: model.id,
                formId: model.formId || "",
                items: items
            }
            params = {
                ..._children
            };
        } else {
            _children = {
                formId: model.formId || "",
                items: items
            }
            if (this.data.type == 'share' || this.data.type == 'sd_share') {
                params = {
                    info: info,
                    children: _children,
                    taskId: this.data.model.taskId
                };
            } else {
                params = {
                    info: info,
                    children: _children
                };
            }
        }

        let url = "";
        let type = this.data.type;
        if (type == 'share') {
            url = "form/reportForward"
        } else if (type == 'sb_share') {
            url = "form/shareReport"
        } else if (type == 'sb_report') {

            url = "declare/report";
        } else {
            url = "form/report"
        }


        // return;
        if (model.id !== "") {
            params.id = model.id;
            url = "form/reportUpdate";
        }
        try {
            const response = await this.$_server(url, {
                data: {
                    ...params,
                    draught: saveType === "draft"
                },
            });
            let {data} = response;
            if (data.code !== 200) {
                throw data;
            }
            if (this.data.type == 'share' || this.data.type == "sb_share") {
                this.clearPageData();
                this.onLoad(this.data.onLoadOption);
                setTimeout(() => {
                    this.setData({
                        "clickNext": true
                    })
                    wx.navigateTo({
                        url: "/pages/home/collection/complete/index"
                    });
                })
            } else {
                if (model.id === "" && saveType !== "draft") {
                    this.confirm();
                } else {
                    setTimeout(() => {
                        wx.askShowToastEx({
                            mask: true,
                            title: data.msg || "保存成功！",
                            duration: 2000,
                            icon: "none",
                            cancel: () => {
                                this.goBack();
                            },
                        });
                    })
                }

                try {
                    let pagetotal = getCurrentPages() //所有的路径 数组
                    // let thispage = pagetotal[pagetotal.length - 1] //当前页面
                    let parpage = pagetotal[pagetotal.length - 2] //父级页面
                    parpage.reloadToatal();
                } catch (e) {
                }


            }
            if (type == 'sb_report') {
                wx.setStorage({
                    key: 'sb_report_reload',
                    data: {
                        value: "1",

                    },
                })
            }


        } catch (error) {
            console.log(error);
            // statements
            if (error.message) {
                wx.askShowToastEx({
                    mask: true,
                    title: error.message,
                    icon: "none",
                    duration: 2000,
                });
            } else {
                throw error;
            }
        }
    },
    clearPageData() {
        const data = {
            model: {
                dataCount: 0,
                state: 2,
                executor: "",
                formId: "",
                shareId: "",
                makePhone: "",
                id: "",
                taskId: "",
                name: "",
                readonly: true,
                line: 0,
                description: "",
            },
            // 表单项列表
            formItemList: [],
            // 单选选中内容
            selectItemValue: {}
        };
        this.setData(data);
    },
    confirm() {
        const beforeClose = action =>
            new Promise(resolve => {
                setTimeout(() => {
                    if (action === "confirm") {
                        this.setData({
                            "clickNext": true
                        })
                        this.clearPageData();
                        setTimeout(() => {
                            this.onLoad(this.data.onLoadOption);
                            resolve(true);
                        });
                    } else {
                        this.goBack();
                        resolve(true);
                    }
                }, 100);
            });

        Dialog.confirm({
            title: "提示",
            message: "是否继续填写下一条？",
            beforeClose,
            cancelButtonText: "完成",
            confirmButtonText: "下一条"
        });
    },
    // 删除行
    deleteRow(e) {
        wx.showModal({
            title: "",
            content: "是否确认删除?",
            success: (res) => {
                if (res.confirm) {
                    const {tableItem, index} = e.currentTarget.dataset;
                    const list = this.data.formItemList;
                    const delRow = (arr) => {
                        for (let i = 0; i < arr.length; i++) {
                            if (arr[i].itemType === 0) {
                                delRow(arr[i].items);
                            } else if (arr[i].itemType === 1 && tableItem.id === arr[i].id) {
                                arr[i].rows.splice(index, 1);
                                break;
                            }
                        }
                    };
                    delRow(list);
                    this.setData({
                        formItemList: list
                    });

                    const data = this.data.model[tableItem.childrenFormId];
                    if (data) {
                        data.splice(index, 1);
                        this.setData({
                            ["model." + tableItem.childrenFormId]: data
                        });
                    }
                }
            }
        })
    },
    // 添加行
    addRow(e) {
        const {tableItem, index} = e.currentTarget.dataset;
        const list = this.data.formItemList;
        const addR = (arr) => {
            for (let i = 0; i < arr.length; i++) {
                if (arr[i].itemType === 0) {
                    addR(arr[i].items);
                } else if (arr[i].itemType === 1 && tableItem.id === arr[i].id) {
                    arr[i].rows.splice(index + 1, 0, {
                        ...arr[i].rows[0],
                        id: this.getRandomId()
                    });
                    break;
                }
            }
        };
        addR(list);

        this.setData({
            formItemList: list
        });
        wx.showToast({
            title: '添加成功',
            icon: "none"
        })
    },
    goBack(callback) {
        wx.navigateBack({
            complete: () => {
                callback && callback();
            },
        });
    },
    onChange(event) {
        if (this.data.isClickAction == true) {
            return
        }
        var that = this;
        this.setData({
            isClickAction: true
        })
        setTimeout(function () {
            that.setData({
                activeNames: event.detail,
                isClickAction: false
            });
        }, 300)

    },
    setValueModel: function (e) {
        console.log(e);
        const {key, valuekindid} = e.currentTarget.dataset;
        var value = e.detail.value;

        //判断pc上输入数字异常
        if (valuekindid == '12' && !this.chk(value)) {
            value = value.slice(0, -1)
        }
        if (valuekindid == '13' && !this.chkd(value)) {
            value = value.slice(0, -1)
        } else {
            if (value.split('.')[1] && value.split('.')[1].length > 2) {
                value = value.slice(0, -1)
            }
        }

        this.setData({
            ["model." + key]: value
        })

    }

});
